package com.orange.modules.dao;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.AuthTestFileSchoolMap;

@Repository
public class AuthTestFileSchoolRepository {
	
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthTestFileSchoolDao authTestFileSchoolDao;
	
	/**
	 * 存专家抽的试题
	 * @param atf
	 * @throws SQLException
	 */
	public void insertAuthTestFileSchool(AuthTestFileSchoolMap atf) throws SQLException{
		authTestFileSchoolDao.save(atf);
	}
	
	/**
	 * c查询试题
	 * @param sid
	 * @param fid
	 * @param cid
	 * @return
	 * @throws SQLException
	 */
	public List<AuthTestFileSchoolMap> queryTestFile(String sid,String fid,String cid) throws SQLException{
		String sql = "SELECT t.p_id as pid,t.s_id as sid,t.f_id as fid,t.s_creattime as createtime,t.c_id as cid FROM t_auth_testfile_school_map t WHERE 1=1 ";
		if(sid!=null && StringUtils.isNotBlank(sid))
			sql+=" AND t.s_id = '"+sid+"'";
		if(fid!=null && StringUtils.isNotBlank(fid))
			sql+=" AND t.f_id = '"+fid+"'";
		if(cid!=null && StringUtils.isNotBlank(cid))
			sql+=" AND t.c_id = '"+cid+"'";
		sql+=" ORDER BY t.p_id asc";
		List<AuthTestFileSchoolMap> list = dbHelper.getBeanList(sql, AuthTestFileSchoolMap.class, null);
		return list;
	}
	
}
